# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=nnn
pkgver=4.9
pkgrel=0
pkgdesc="The unorthodox terminal file manager"
url="https://github.com/jarun/nnn"
arch="all"
license="BSD-2-Clause"
makedepends="musl-fts-dev ncurses-dev readline-dev"
install="$pkgname-plugins.post-install"
options="!check"  # no tests provided and $(nnn -v) requires tty
subpackages="$pkgname-doc
	$pkgname-plugins::noarch
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="https://github.com/jarun/nnn/archive/v$pkgver/nnn-$pkgver.tar.gz
	nnn-getplugs
	musl-fts-support.patch
	"

build() {
	make
}

package() {
	make install DESTDIR="$pkgdir" PREFIX=/usr

	install -D -m 644 misc/auto-completion/bash/nnn-completion.bash \
		"$pkgdir"/usr/share/bash-completion/completions/$pkgname

	install -D -m 644 misc/auto-completion/fish/nnn.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/$pkgname.fish

	install -D -m 644 misc/auto-completion/zsh/_nnn \
		"$pkgdir"/usr/share/zsh/site-functions/_$pkgname
}

plugins() {
	pkgdesc="nnn official plugins"
	local destdir="$subpkgdir/usr/share/$pkgname/plugins"

	cd "$builddir"
	mkdir -p "$destdir"
	cp -r plugins "${destdir%/*}"/

	cd "$destdir"
	rm README* getplugs

	install -D -m 0755 "$srcdir"/nnn-getplugs "$destdir"/getplugs
	mkdir -p "$subpkgdir"/usr/bin
	ln -s ../share/$pkgname/plugins/getplugs "$subpkgdir"/usr/bin/nnn-getplugs
}

sha512sums="
3c16ed1cbc5466b05306e38c6f5d8eb7ade9cf5ad766f9ff3bf7d20d5bfb9bdf1564527e27191e2cd85542c25245f338e1236630de3d1c8e5fbd10d54d628a14  nnn-4.9.tar.gz
5870bd38c897c0738778952d3c65131ae37b44d8a5032add81645bcf46cae4c66700f319b514f8ab369e15900e4de1058736664ca3603a850ef0212a8ce8e7ee  nnn-getplugs
024b569085e49c33c8fd4143ef97d1b96402e08acb7477f06a2de33f663843151c364f6d7c20329396cadbf75100255f70b28da5f2f44326880d34a3c4644a20  musl-fts-support.patch
"
